<?php
/**
 * open.taobao.com
 */

class openTaoBao
{
	public $base_url = "http://container.api.taobao.com/container/identify?";
	public $app_key = "";
	public $app_secret = "";
	public $encode = "utf-8";
	public $param = array();
	public $callback_url = "";

	public function __construct($app_key, $app_secret, $callback_url)
	{
		$this->app_key = $app_key;
		$this->app_secret = $app_secret;
		$this->callback_url = $callback_url;
	}
	
	public function createSign(){
	    $sign = $this->app_secret; 
	    ksort($this->param); 
	    foreach ($this->param as $key => $val) { 
	       if ($key !='' && $val !='') { 
	           $sign .= $key.$val; 
	       } 
	    } 
	    $sign = strtoupper(md5($sign.$this->app_secret));
	    return $sign; 
	}
	
	public function createStrParam() { 
	    $strParam = ''; 
	    foreach ($this->param as $key => $val) { 
	       if ($key != '' && $val !='') { 
	           $strParam .= $key.'='.urlencode($val).'&'; 
	       } 
	    } 
	    return $strParam; 
	} 
	
	public function api($url, $timeout=5)
	{
	    $ch = curl_init();
		curl_setopt ($ch, CURLOPT_URL, $url);
		curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); 
		curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
		$file_contents = curl_exec($ch);
		curl_close($ch);
		return $file_contents;
	}
}
?>